package server;

import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import model.TkInfo;
import server.Service;

import java.util.logging.Level;
import java.util.logging.Logger;


public class MachineServerHandler extends ChannelHandlerAdapter {
	private static final Logger logger = Logger.getLogger(MachineServerHandler.class.getName());
	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg)throws Exception {
		logger.log(Level.INFO, "SERVER接收到客户端信息......");
		TkInfo msgs = (TkInfo) msg;
		Service.doMsgRecieved(msgs,ctx);
	}
	@Override
	public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
		ctx.flush();//将消息队列中的消息写入到SocketChannel中发送给对方
	}
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
		ctx.close();//异常发生时，关闭ChannelHandlerContext相关句柄
	}
}
